/*
 *  $Id: PlayerGraveyard.cs 961 2009-12-08 22:20:20Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

using AgateLib.Geometry;

namespace Ragima {
    /// <summary>
    /// Содержимое таба, определяющее могильник игрока
    /// </summary>
    public class PlayerGraveyardTabContent: TabContent {
        private Player _player;
        private List<Region> _regions;

        public PlayerGraveyardTabContent(Player player): base(TabType.Graveyard, false) {
            _player = player;
            _regions = new List<Region>();
            for (int i = 0; i < Constants.FieldSize; i++)
                _regions.Add(new PlayerGraveyardRegion(Constants.GetRowRect(i, 3), this, i));
        }

        public static PlayerGraveyardTabContent GetContent(Tabs tabs, Player player) {
            PlayerGraveyardTabContent content = null;
            if (tabs != null) content = tabs.FindContent<PlayerGraveyardTabContent>(delegate(PlayerGraveyardTabContent other) {
                return other.Player == player;
            });
            return content != null ? content : new PlayerGraveyardTabContent(player);
        }

        public Player Player { get { return _player; } }

        public override int Count {
            get { return _player.Graveyard.Count; }
        }

        public override IEnumerable<Region> GetRegions() {
            for (int i = 0; i < CountFromPosition; i++)
                yield return _regions[i];
        }

        public GraveyardItem GetItem(int num) {
            int index = GetIndex(num);
            return (index >= 0 && index < Count) ? _player.Graveyard[index] : null;
        }
    }

    /// <summary>
    /// Регион, определяющий местность у игрока
    /// </summary>
    public class PlayerGraveyardRegion: HelpRegion {
        private PlayerGraveyardTabContent _content;
        private int _num;

        public PlayerGraveyardRegion(Rectangle rect, PlayerGraveyardTabContent content, int num): base(rect) {
            _content = content;
            _num = num;
        }

        public Player Player { get { return _content.Player; } }
        public GraveyardItem Item { get { return _content.GetItem(_num); } }

        public override void Draw() {
            GraveyardItem item = Item;
            if (item == null) return;
            item.Card.DrawSmall(Rect.X, Rect.Y);
            Data.Fonts.CardHealth.Draw(Rect.X + 2, Rect.Y + Constants.SmallCardHeight - 17, string.Format(" {0}/{1} ", item.Damage, item.Health));
        }
        public override void DrawTarget() {
            Draw();
            Data.CardSelect1.Draw(Rect.Location);
        }

        public override IHelpProvider HelpObject {
            get {
                GraveyardItem item = Item;
                return item != null ? item.Card : null;
            }
        }
    }
}